
package com.contractmodule.servlet;
import com.contractmodule.bean.TbProjectState;
import com.contractmodule.dao.*;
import com.usersmodule.bean.TbUsers;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import util.*;

public class TbProjectStateServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        int userId=((TbUsers) request.getSession().getAttribute("Users")).getUserId(); 
        if("add".equals(method)){
        int isFinish=Integer.parseInt(request.getParameter("isFinish"));
        int initialTest=Integer.parseInt(request.getParameter("initialTest"));
        String completionData=request.getParameter("completionData");
        int isPaperReview=Integer.parseInt(request.getParameter("isPaperReview"));
        int isElectronicProcesses=Integer.parseInt(request.getParameter("isElectronicProcesses"));
        int flowProcessId=Integer.parseInt(request.getParameter("flowProcessId"));
        int isInvoice=Integer.parseInt(request.getParameter("isInvoice"));
        String invoiceTime=request.getParameter("invoiceTime");
        int isBackSection=Integer.parseInt(request.getParameter("isBackSection"));
            if(new TbProjectStateDAO().add(new TbProjectState(isFinish,initialTest,completionData,isPaperReview,isElectronicProcesses,flowProcessId,isInvoice,invoiceTime,isBackSection,userId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_ProjectState", "ProjectStateId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int projectStateId=Integer.parseInt(request.getParameter("projectStateId"));
        int isFinish=Integer.parseInt(request.getParameter("isFinish"));
        int initialTest=Integer.parseInt(request.getParameter("initialTest"));
        String completionData=request.getParameter("completionData");
        int isPaperReview=Integer.parseInt(request.getParameter("isPaperReview"));
        int isElectronicProcesses=Integer.parseInt(request.getParameter("isElectronicProcesses"));
        int flowProcessId=Integer.parseInt(request.getParameter("flowProcessId"));
        int isInvoice=Integer.parseInt(request.getParameter("isInvoice"));
        String invoiceTime=request.getParameter("invoiceTime");
        int isBackSection=Integer.parseInt(request.getParameter("isBackSection"));
            if(new TbProjectStateDAO().edit(new TbProjectState(projectStateId,isFinish,initialTest,completionData,isPaperReview,isElectronicProcesses,flowProcessId,isInvoice,invoiceTime,isBackSection,userId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method)) goList(request, response);
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbProjectState",new TbProjectStateDAO().getTbProjectStateByProjectStateId(Integer.parseInt(request.getParameter("projectStateId"))));
            response.sendRedirect("ContractModule/TbProjectStateOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession(true).removeAttribute("tbProjectState");
            response.sendRedirect("ContractModule/TbProjectStateOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbProjectStateList",new TbProjectStateDAO().getTbProjectStateAll());
        response.sendRedirect("ContractModule/TbProjectStateList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
